﻿using System;
using nRoute.Components.Composition;
using nRoute.Internal;

namespace nRoute.Services
{
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly,
        AllowMultiple = true, Inherited = false)]
    public class DefineServiceAttribute
		 : MapServiceAttribute
    {
        private readonly Type _implementationType;

        public DefineServiceAttribute(Type serviceType, Type implementationType, params Type[] dependencies)
		 : this(serviceType, implementationType, null, dependencies) { }

        public DefineServiceAttribute(Type serviceType, Type implementationType, string name, params Type[] dependencies)           
		 : base(serviceType, name, dependencies)
        {
            Guard.ArgumentNotNull(implementationType, "implementationType");
            EnsureIsServiceType(implementationType, serviceType);
            
            // save this
            _implementationType = implementationType;
        }

#region Overrides

        protected internal override IResourceLocator GetResourceLocator(Type targetType)
        {
            return base.GetResourceLocator(_implementationType);
        }

#endregion

    }
}
